package com.nbgroup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.nbgroup.mapper.NoticeMapper;
import com.nbgroup.pojo.common.PageResult;
import com.nbgroup.pojo.dto.PageDTO;
import com.nbgroup.pojo.vo.NoticeVo;
import com.nbgroup.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public PageResult notice0(PageDTO dto) {
        dto.check();
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<NoticeVo> p = noticeMapper.notice0(dto);

        PageResult pageResult = new PageResult();
        pageResult.setRows(p.getResult());
        pageResult.setTotal(p.getTotal());
        pageResult.setCode(200);
        pageResult.setMsg("查询成功");
        return pageResult;
    }

    @Override
    public PageResult notice1(PageDTO dto) {
        dto.check();
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<NoticeVo> p = noticeMapper.notice1(dto);

        PageResult pageResult = new PageResult();
        pageResult.setRows(p.getResult());
        pageResult.setTotal(p.getTotal());
        pageResult.setCode(200);
        pageResult.setMsg("查询成功");
        return pageResult;
    }

    @Override
    public NoticeVo getInfo(Integer id) {
        return noticeMapper.getInfo(id);
    }
}
